package com.chenyun.system.controller;

import com.chenyun.system.model.SysRegion;
import com.chenyun.system.service.ISysRegionService;
import com.chenyun.system.vo.TreeSelect;
import com.chenyun.boot.web.controller.BaseController;
import com.chenyun.common.vo.AjaxResult;
import com.chenyun.tenant.aop.TenantIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * SysRegionController：
 * Description:
 *
 * @author: Lonni
 * @date: 2022/11/8 0008 15:25
 */
@RestController
@Slf4j
@RequestMapping("region")
@RequiredArgsConstructor
@Api(tags = "省市区-admin")
@TenantIgnore
public class SysRegionController extends BaseController<ISysRegionService, SysRegion> {
    private final ISysRegionService sysRegionService;

    @GetMapping("getProvince")
    @ApiOperation(value = "获取省份")
    public AjaxResult getProvinces() {
        return toAjax(sysRegionService.getProvinces());
    }


    @GetMapping("getCity/{proId}")
    @ApiOperation(value = "获取市")
    public AjaxResult getCityByPro(@PathVariable("proId") @Valid @NotBlank String proId) {
        return toAjax(sysRegionService.getCityByProId(proId));
    }

    @GetMapping("getArea/{cId}")
    @ApiOperation(value = "获取区")
    public AjaxResult getAreaByCity(@PathVariable("cId") @Valid @NotBlank String cId) {
        return toAjax(sysRegionService.getAreaByCityId(cId));
    }

    @GetMapping("treeSelect")
    @ApiOperation(value = "获取省市区(树形结构)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "level",value = "获取层级 1 2 3",dataType = "String")
    })
    public AjaxResult<List<TreeSelect>> treeSelect(String level) {
        return AjaxResult.SUCCESS(sysRegionService.builderTreeSelect(level));
    }

}



